package com.lib.utils;

import android.util.Log;

import java.io.Closeable;

/**
 * <pre>
 *     author: Blankj
 *     blog  : http://blankj.com
 *     time  : 2016/10/9
 *     desc  : 关闭相关工具类
 * </pre>
 */
public class CloseUtils {
    private CloseUtils() {

    }

    /**
     * 关闭IO
     *
     * @param closeables closeable
     */
    public static void close(Closeable... closeables) {

        if (closeables == null)
            return;
        for (Closeable closeable : closeables) {
            if (closeable != null) {
                try {
                    closeable.close();
                } catch (Exception e) {
                    XLog.w(Log.getStackTraceString(e));
                }
            }
        }
    }

    /**
     * 安静关闭IO
     *
     * @param closeables closeable
     */
    public static void closeIOQuietly(AutoCloseable... closeables) {
        if (closeables == null)
            return;
        for (AutoCloseable closeable : closeables) {
            if (closeable != null) {
                try {
                    closeable.close();
                } catch (Exception e) {//
                }
            }
        }
    }
}
